
import java.awt.AWTEventMulticaster;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JTextField;

/**
 *
 * @author -
 */
public class Example {

    public static void main(String[] args) {
        RootFrame root = new RootFrame();
        root.setVisible(true);

    }

    public static class ChildEvent {

        private String message;

        public ChildEvent(String message) {
            this.message = message;
        }

        public String getMessage() {
            return message;
        }
    }

    public static class ChildrenActionListener implements EventListener {

        JTextField field;

        void setIndicator(JTextField f) {
            field = f;
        }

        void onChildEvent(ChildEvent evt) {
            if (field != null) {
                field.setText(evt.getMessage());
            }
        }
    }

    /**
     * Р РѕРґРёС‚РµР»СЊСЃРєР°СЏ С„РѕСЂРјР°
     */
    public static class RootFrame extends JFrame {

        ChildrenActionListener listener = new ChildrenActionListener();

        public RootFrame() {
            super("Pum");
            setPreferredSize(new Dimension(300, 300));
            setLocation(new Point(100, 100));
            getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.LINE_AXIS));
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //            
            JTextField indicator = new JTextField();
            listener.setIndicator(indicator);
            //
            JButton button = new JButton("KRum");
            button.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    ChildFrame child = new ChildFrame(listener);
                    child.setVisible(true);
                }
            });
            //
            getContentPane().add(indicator);
            getContentPane().add(button);
            pack();
        }

    }

    /**
     * Р”РѕС‡РµСЂРЅСЏСЏ С„РѕСЂРјР°
     */
    public static class ChildFrame extends JFrame {

        private ChildrenActionListener listener = null;

        public ChildFrame(ChildrenActionListener var) {
            super("PUR");
            this.listener = var;
            setPreferredSize(new Dimension(300, 300));
            setLocation(new Point(400, 400));
            setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            //
            final JCheckBox box = new JCheckBox("PRum");
            box.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    listener.onChildEvent(new ChildEvent("" + box.isSelected()));
                }
            });

            //
            getContentPane().add(box);
            pack();
        }

    }

}
